//原型 三月联赛：https://reeeaz.axshare.com
//接口 http://122.9.18.126:4999/web/#/142/2043
<script setup>
import { onMounted } from 'vue'
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'
import { jsonp } from 'vue-jsonp'
const router = useRouter()
const store = useStore()
store.commit('getInfect')
const common = store.state.common.obj
store.commit('getIsAnchor', common.userId >= 300000 && common.userId < 500000 ? true : false)
const isAnchor = common.userId >= 300000 && common.userId < 500000 ? true : false
const api = store.state.api

// store.commit('getFirst', false)
console.log('views/index/index.vue',common);
// 总路由
const routes = [
    {
        route: 'welfare',
        name: '联赛福利'
    },
    {
        route: 'ceremony',
        name: '春季联赛'
    },
    {
        route: 'list',
        name: '最佳榜单'
    },
]
router.replace('/welfare')
// 赛段定位
const getCur = async () => {
    await api.gameStage().then(res => {
        // res = {
        //     data: {
        //         "errcode": 0,
        //         "result": 4,
        //         "errmsg": "",
        //         "status": 200
        //     }
        // }
        if (res.data.status == 200) {
            let data = res.data.result
            if (data > -1) {
                store.commit('getCur', data)
                router.replace('/ceremony')
            }
        }
    })
}

// 获取用户信息
const getUserInfo = async () => {
    await jsonp('https://datacenter.qxiu.com/cgi/user/info?userId=' + common.userId).then(res => {
        if (res.result) store.commit('getUserInfo', res.result.info)
    })
}
// 获取用户信息
const getAnchorInfo = async () => {
    await jsonp('https://datacenter.qxiu.com/cgi/anchor/info?anchorId=' + (isAnchor ? common.userId : common.anchorId)).then(res => {
        if (res.result){
            store.commit('getAnchorInfo',res.result.info)
        }
    })
}

onMounted(() => {
    getUserInfo()
    getAnchorInfo()
    getCur()
})
</script>

<template>
    <div class="home">
        <div class="header"></div>
        <ul class="topTab">
            <router-link v-for="(item, index) in routes" :key="index" :to="'/' + item.route" custom
                v-slot="{ navigate, isActive }">
                <li @click="navigate" :class="{ active: isActive }"> </li>
            </router-link>
        </ul>
        <div class="center">
            <router-view />
        </div>
        <div class="ios" v-if="store.state.isiOS">本活动与苹果公司无关</div>
        <div class="toastTip_box" v-if="store.state.isTips">
            <p class="toastTip">{{ store.state.tips }}</p>
        </div>
    </div>
</template>

<style lang='scss' scoped></style>
